package com.excel.read;

import java.io.IOException;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import jxl.write.WriteException;

import com.excel.DB;

public class SQLGridTableConfig extends ExcelConfig {
	
	private SQLTableConfig sqlTableConfig;
	private ExcelTableConfig gridSearchConfig;
	
	/**
	 * 初始化SQLEntity
	 */
	private void initSQLEntity() {
		Iterator iterator = AllTable.sqlMap.keySet().iterator();
		while(iterator.hasNext()) {
			String key = (String) iterator.next();
			SQLTable sqlTable = Config.getSQLTable(key);
			Iterator itr =  sqlTable.getSqlMap().keySet().iterator();
			//
			while(itr.hasNext()) {
				String sqlId = (String)itr.next();
				GridSearchTable gridSearchTable = Config.getGridSearchTable(sqlId);
				SQLEntity sqlEntity = new SQLEntity();
				DB db = new DB();
//				try {
//					 String sql = sqlTable.getSQL(sqlId);
//					 List<QueryNode> queryNodeList = db.init2(gridSearchTable, sql);
//					 sqlEntity.nodeList = queryNodeList;
//				} catch (WriteException e1) {
//					e1.printStackTrace();
//				} catch (IOException e1) {
//					e1.printStackTrace();
//				} 
				sqlTable.putSQLEntity(sqlId, sqlEntity);
			}
		}
	}
	
	public String tableConfig(String realPath) {
		sqlTableConfig = new SQLTableConfig();
//		gridSearchConfig = new ExcelTableConfig();
//		gridSearchConfig.tableConfig(realPath);
		sqlTableConfig.tableConfig(realPath);				   
		
		this.initSQLEntity();
		
		return realPath;
	}
	
}
